// File:    TnExtensionTools.cs
// Author:  HT
// Created: Tuesday, October 18, 2011 10:19:24 AM
// Purpose: Definition of Class TnExtensionTools

using System;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.esriSystem;

namespace Tayninh2011
{
    public abstract class TnExtensionTools
    {
        protected string name;
        protected ITnExMemDataManager _mem4DataManager;

        public ITnExMemDataManager Mem4DataManager
        {
            get { return _mem4DataManager; }
            
        }

        public string Name
        {
            get
            {
                return name;
            }
        }
        //constructor
        public TnExtensionTools()
        {
            this._mem4DataManager = new TnExMemory();
            this._mem4DataManager.TempPath = "C:/tayninh/temp";
            this._mem4DataManager.TempMdb="tempmdb.mdb";
            this._mem4DataManager.TempFullPath = "C:/tayninh/temp/tempmdb.mdb/";
            this._mem4DataManager.TempFullPathNoEnd = "C:/tayninh/temp/tempmdb.mdb";
        }

        protected virtual void runTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC)
        {

            // Set the overwrite output option to true
            geoprocessor.OverwriteOutput = true;

            // Execute the tool            
            try
            {
                geoprocessor.Execute(process, TC);
                ReturnMessages(geoprocessor);

            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
                ReturnMessages(geoprocessor);
            }
        }
        protected virtual void runTool(Geoprocessor geoprocessor, IGPProcess process, IVariantArray param, ITrackCancel TC)
        {

            // Set the overwrite output option to true
            geoprocessor.OverwriteOutput = true;

            // Execute the tool            
            try
            {
                geoprocessor.Execute("Clip_analysis", param, TC);
                ReturnMessages(geoprocessor);

            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
                ReturnMessages(geoprocessor);
            }
        }
        protected virtual void ReturnMessages(Geoprocessor gp)
        {
            if (gp.MessageCount > 0)
            {
                for (int Count = 0; Count <= gp.MessageCount - 1; Count++)
                {
                    Console.WriteLine(gp.GetMessage(Count));
                }
            }

        }
    }
}
